1. Field of the Invention
The present invention generally relates to improvements in Prolog software and, more particularly, to an implementation of Prolog, hereinafter referred to as P++ software, that introduces two structure types into arguments of clauses, and improves built-in Prolog predicates assert and retract. The invention also provides the ability of P++ software to perform addition, subtraction, and multiplication of matrices.
2. Description of the Related Art
Conventional programming is based on the concept of giving specific commands to the computer about how to solve a particular problem. Prolog is an example of attempts to make the process of human-computer communication significantly different in style. It tries to achieve the goal of requiring the user to describe the problem in a logically coherent and correct manner, leaving it to the computer to work out and execute the necessary steps for solving the problem. Though Prolog does not fully realize this aim, it is a significant step towards this new style of declarative or descriptive programming.
An appealing characteristic of Prolog is that the emphasis in writing a Prolog program is on specifying or describing the nature of the problem, rather than on spelling out the steps the computer should take to solve the problem, as one is required to do with conventional languages like BASIC or COBOL or Pascal. This difference, that makes Prolog markedly different, is often described by saying that Prolog is a declarative or assertional language, as contrasted with conventional languages, which are usually called imperative. The present invention is P++ software, an implementation of Prolog that introduces two structure types into arguments of clauses, and improves built-in Prolog predicates assert and retract. P++ software also extends the algebraic operations of addition, subtraction and multiplication to matrices.
The related art is represented by the following patents of interest.
U.S. Pat. No. 4,546,432, issued on Oct. 8, 1985 to Mamoru Umemura et al., describes a Prolog processing system. Umemura et al. do not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 4,648,044, issued on Mar. 3, 1987 to Steven Hardy et al., describes a basic expert system tool. Hardy et al. do not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,129,081, issued on Jul. 7, 1992 to Kenzo Kobayashi et al., describes a system for processing data using logic language. Kobayashi et al. do not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,274,820, issued on Dec. 28, 1993 to Marc J. L. Gillett, describes a method and system for eliminating operating codes from intermediate Prolog instructions. Gillett ""820 does not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,321,833, issued on Jun. 14, 1994 to Shih-Chio Chang et al., describes a method for adaptive multilevel record ranking for full text information retrieval systems, whereby retrieved records are quantitatively ranked with respect to their relevance to the terms of a query and wherein a user specifies relevance factors for a relative weighting of the relevance factors on each level. Chang et al. do not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,386,520, issued on Jan. 31, 1995 to Marc J. L. Gillett, describes an improved technique for processing Prolog objects. Gillett ""520 does not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,396,632, issued on Mar. 7, 1995 to Marc J. L. Gillett, describes an improved architecture for a Prolog interpreter/compiler. Gillett ""632 does not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,572,670, issued on Nov. 5, 1996 to Timothy L. Puckett, describes a method and apparatus for translation between low level data records having both interrelated time dependencies and having a large plurality of varying formats, and high level data having English, English-like or, more generally, natural language terms where statements or this latter data are not interrelated by time dependencies and such that the data format is substantially fixed and uniform. Puckett does not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,696,980, issued on Dec. 9, 1997 to Christopher H. Brew, describes a machine translation system which operates by analyzing a source text to deduce information about the usage and meaning of the words of a source language text as they occur in context. Brew does not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,712,960, issued on Jan. 27, 1998 to Carlo Chiopris et al., describes a system and method for intelligent database management using abductive reasoning. Chiopris et al. do not suggest Prolog software according to the claimed invention.
U.S. Pat. No. 5,742,806, issued on Apr. 21, 1998 to David Reiner et al., describes an improved architecture for a Prolog interpreter/compiler. Reiner et al. do not suggest Prolog software according to the claimed invention.
The abstract from a master thesis by R. P. White, entitled Natural Language Interface for a PROLOG Database, published on Dec. 16, 1983, describes a natural language interface to a relational database wherein careful attention was given to the human factors needed to aid a novice user in accessing data. The White abstract does not suggest Prolog software according to the claimed invention.
None of the above inventions and patents, taken either singularly or in combination, is seen to describe the instant invention as claimed.
The present invention is P++ software, an implementation of Prolog that introduces two structure types into arguments of clauses, and improves the built-in Prolog predicates assert and retract. P++ software adds structure types Tuple and Phrase to Prolog. These two structure types are logically the same as List in Prolog. They require lexical analysis, engine storage, unification, and output. The structure types Tuple and Phrase each require a counterpart for everything that is done for List. The changes are extensive.
Phrase is defined as a sequence of Terms. One space separates two Terms. A Phrase can be instantiated, or unified as a single Term or as a sequence of Terms of its length. A Phrase can be inserted into another Phrase. The result is a Phrase. The Functor of the Phrase is defined as xe2x80x98 . . xe2x80x99. The Arity of the Phrase is defined as the count of Terms in the sequence. The Functor of an expression with operators can be viewed firstly as an outmost one in the expression just as in Prolog, and secondly as the Functor of a Phrase. The argument also has two meanings when referring to argument 1 or argument 2. The Arity of a Phrase can be changed if it contains a variable and which may later be instantiated to another Phrase. A Phrase is useful for processing a natural language and performing linguistic analysis.
Tuple is defined as a sequence of Terms separated by commas and the sequence is enclosed by parentheses. A Tuple can be instantiated or unified singly or component wisely. The Functor of a Tuple is defined as xe2x80x98 . . . xe2x80x99. The Arity of a Tuple is defined as a count of Terms in the sequence within its parentheses. If an expression with operators is in parentheses, it is considered as a Phrase inside a Tuple. Unlike Phrase and List, the number of members in a Tuple never changes. This property is useful in a database application. The two new structure types Phrase and Tuple are on the same level as List and Compound Term which are structure types in Prolog. These four structure types can be combined and used up to the order as high as the resource allows. Hence users have more formats to store and retrieve data for practical use.
The present invention provides the ability of P++ software to perform addition, subtraction, and multiplication of matrices. A row matrix has the form (T1, T2, . . . , TN) where each Ti is a term. The dimension of this row matrix is 1 by N. A column matrix has the form ((T1) (T2) . . . (TM)) where each Ti is a term. The dimension of this column matrix is M by 1. An M by N matrix is a special Tuple. It has the form (ROW1 ROW2 . . . ROWM) where each ROWi is a row matrix of dimension 1 by N. The multiplication result of X and Y is returned in the following way: (1) if X is a number and Y is a number, a number is returned; (2) if X is a constant and Y is a matrix of m by n, a matrix of m by n is returned; (3) if X is a matrix of m by n and Y is a constant, a matrix of m by n is returned; (4) if X is a matrix of m by k and Y is a matrix of k by n, a matrix of m by n is returned; (5) otherwise, nothing is changed. The numerical sum of X and Y is returned only if X and Y are both instantiated to numbers. If X and Y are matrices of the same dimension, the matrix addition is performed and the result matrix is returned. In any other case nothing is changed. The numerical difference of X and Y is returned only if X and Y are both instantiated to numbers. If X and Y are matrices of the same dimension, the matrix subtraction is performed and the result matrix is returned. In any other case nothing is changed.
The built-in Prolog predicate assert is changed and enhanced as follows. Each goal in the added rule can be instantiated right before the rule is added. The flexibility is that the added rule is not decided at design time but at run time. In asserta (H,B1,B2, . . . ,Bn) the clause to be added is of the form xe2x80x9cH:-B1,B2, . . . ,Bn.xe2x80x9d as a rule or xe2x80x9cH.xe2x80x9d as a fact. H composes the head of the clause and the rest of the arguments B1,B2, . . . Bn form the body of the clause. The goal fails if an argument is not instantiated to a compound term or an atom, otherwise it succeeds. If the clause to be added is not the same as the first one in the database then it is added to the beginning of the database. In case that xe2x80x9c;xe2x80x9d or xe2x80x9cxe2x86x92xe2x80x9d is needed, it is put as an argument in single quotes. It can only be used in a directive, or a query, or the body of a rule, e.g., xe2x80x9c:-asserta(h(X),X=1,xe2x80x98;xe2x80x99,X=2).xe2x80x9d asserts the rule xe2x80x9ch(X):-X=1;X=2.xe2x80x9d to the database of the predicate h with Arity 1.
In xe2x80x9casserti(ith,H,B1,B2, . . . ,Bn).xe2x80x9d the clause to be added is of the form xe2x80x9cH:-B1,B2, . . . Bn.xe2x80x9d as a rule or xe2x80x9cH.xe2x80x9d as a fact. The first argument ith is the index and it ranges from 1 to the index of the current last clause. The goal fails if this argument is not a number or is not in the range. H composes the head of the clause and the rest of the arguments B1,B2, . . . Bn form the body of the clause. The goal fails if any of H,B1, . . . ,Bn is not instantiated to a compound term or an atom, otherwise it succeeds. If the clause to be added is not the same as the ith one in the database then it is added to the ith place of the database. In case that xe2x80x9c;xe2x80x9d or xe2x80x9cxe2x86x92xe2x80x9d is needed, it is put as an argument in single quotes. It can only be used as a directive, or a query, or the body of a rule, e.g., xe2x80x9c:-asserti(2,h(X),X=1,xe2x80x98;xe2x80x99,X=2).xe2x80x9d asserts the rule xe2x80x9ch(X):-X=1;X=2.xe2x80x9d to the second place of the database of the predicate h with arity 1. Here it is assumed that at least one such clause already exists.
In assertz(H,B1,B2, . . . ,Bn) the clause to be added is of the form xe2x80x9cH:-B1,B2, . . . ,Bn.xe2x80x9d as a rule or xe2x80x9cH.xe2x80x9d as a fact. H composes the head of the clause and the rest of the arguments B1,B2, . . . ,Bn form the body of the clause. The goal fails if an argument is not instantiated to a compound term or an atom, otherwise it succeeds. If the clause to be added is not the same as the last one in the database then it is added to the end of the database. In case that xe2x80x9c;xe2x80x9d or xe2x80x9cxe2x86x92xe2x80x9d is needed, it is put as an argument in single quotes. It can only be used in a directive, or a query, or the body of a rule, e.g., xe2x80x9c:-assertz(h(X),X=1,xe2x80x98;xe2x80x99,X=2).xe2x80x9d asserts the rule xe2x80x9ch(X):-X=1;X=2.xe2x80x9d to the end of the database of the predicate h with Arity 1.
P++ software keeps retracta/1 and retractz/1 the same as ANSI Prolog 13211-1. One enhancement occurs in the form of retracti(ith,X). The first argument ith is the index and it ranges from 1 to the index of the current last clause. The goal fails if this argument is not a number or is not in the range. X must be instantiated to the form name/arity, otherwise it fails. It also fails if no such clause exists in the database. This goal removes the ith clause (in the database) of the name and the Arity. It can only be used in a directive, or a query, or the body of a rule. Another enhancement occurs in the form of retract (H,B1,B2, . . . ,Bn) The clause to be retracted is of the form xe2x80x9cH:-B1,B2, . . . ,Bn.xe2x80x9d as a rule or xe2x80x9cH.xe2x80x9d as a fact. H composes the head of the clause and the rest of the arguments B1,B2 . . . ,Bn form the body of the clause. The goal fails if an argument is not instantiated to a compound term or an atom. The goal succeeds if there exists a clause in the database which is the same as the one to be retracted. Only the first matched clause is retracted. It fails if no such clause exists. In case that xe2x80x9c;xe2x80x9d or xe2x80x9cxe2x86x92xe2x80x9d is needed, it is put as and argument in single quotes. It can only be used in a directive, or a query, or the body of a rule.
Accordingly, it is a principal object of the invention to provide an implementation of Prolog software that adds a new structure type, adds a modified structure type, and improves built-in Prolog predicates assert and retract.
It is another object of the invention to provide an implementation of Prolog software that extends the algebraic operations of addition, subtraction and multiplication to matrices.
It is an object of the invention to provide improved elements and arrangements thereof in an implementation of Prolog software for the purposes described which is inexpensive, dependable and fully effective in accomplishing its intended purposes.